--kopisusu.game
--[[
MIT License

Copyright (c) 2023 Anggara Yama Putra

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]
-- Globals
AnggaraNothing = AnggaraNothing or {}
do
end

-- module: AnggaraNothing.KopiSusu.Events
do
  AnggaraNothing.KopiSusu.Events = AnggaraNothing.KopiSusu:CreateProxy( Game.Rule,
    {
      -- CGameRule
      {'OnRoundStart'},
      {'OnRoundStartFinished'},
      {'OnUpdate'},
      -- CBaseMonster
      {'OnTakeDamage', {[1] = 4,}}, -- 4 = damage
      {'OnKilled'},
      -- CBasePlayer
      {'OnPlayerConnect'},
      {'OnPlayerDisconnect'},
      {'OnPlayerJoiningSpawn'},
      {'OnPlayerSpawn'},
      {'OnPlayerAttack', {[1] = 4,}}, -- 4 = damage
      {'OnPlayerKilled'},
      {'OnPlayerSignal'},
      -- CBasePlayerWeapon
      {'CanBuyWeapon'},
      {'CanHaveWeaponInHand'},
      {'OnGetWeapon'},
      {'OnSwitchWeapon'},
      {'OnDeployWeapon'},
      {'PostFireWeapon'},
      {'OnReload'},
      {'OnReloadFinished'},
      -- Voxel GameSave
      {'OnReceiveGameSave'},
      {'OnLoadGameSave'},
      {'OnGameSave'},
      {'OnClearGameSave'},
    }
  )
end

--[[ tests
do
  local dprint = log or print
  local Events = AnggaraNothing.KopiSusu.Events
  local Rule = Game.Rule

  Rule.user.okboomer = 1
  assert( Events.user.okboomer == 1, '[Proxy-2-Source] failed at __newindex' )
  Events.user.okboomer = 2
  assert( Rule.user.okboomer == 2, '[Source-2-Proxy] failed at __index' )

  local temp
  function Events:OnUpdate (_)
    dprint( 'Game.Rule.OnUpdate #1' )
    temp = 1
  end
  function Events:OnUpdate (_)
    dprint( 'Game.Rule.OnUpdate #2' )
    temp = 2
  end
  local function HandledOnUpdate (_)
    dprint( 'Game.Rule.OnUpdate #4 handled' )
    assert( temp == 1, '[HandledOnUpdate] failed to execute' )
    Events.OnUpdate:Clear()
    return AnggaraNothing.KopiSusu.handled()
  end
  function Events:OnUpdate (_)
    dprint( 'Game.Rule.OnUpdate #3 assert' )
    assert( temp == 2, '[OnUpdate] failed to execute' )
    Events.OnUpdate:Insert( 2, HandledOnUpdate )
  end

  function Events:OnTakeDamage (...)
    dprint( 'Generic OnTakeDamage' )
  end

  function Events:OnPlayerAttack (_, _, damage, _, _)
    dprint( 'Game.Rule.OnPlayerAttack #1' )
    return damage
  end
  function Events:OnPlayerAttack (_, _, damage, _, _)
    dprint( 'Game.Rule.OnPlayerAttack #2 overridden' )
    return AnggaraNothing.KopiSusu.overridden( 1337 )
  end
  local function OneTimeOnTakeDamage (self, victim, _, damage, _, _)
    if not victim or not victim:IsPlayer() then
      return
    end
    dprint( 'Game.Rule.OnTakeDamage #5 assert' )
    assert( damage|0 == 7331, '[OneTimeOnTakeDamage] failed to execute' )
    Events.OnTakeDamage:Clear()
  end
  local function HandledOnPlayerAttack (self, _, _, damage, _, _)
    dprint( 'Game.Rule.OnPlayerAttack #4 handled' )
    assert( damage|0 ~= 1337, '[HandledOnPlayerAttack] failed to execute' )
    Events.OnPlayerAttack:Clear()
    return AnggaraNothing.KopiSusu.handled( 7331 )
  end
  function Events:OnPlayerAttack (_, _, damage, _, _)
    dprint( 'Game.Rule.OnPlayerAttack #3 assert' )
    assert( damage == 1337, '[OnPlayerAttack] failed to execute' )
    Events.OnPlayerAttack:Insert( 2, HandledOnPlayerAttack )
    --Events.OnTakeDamage:Append( OneTimeOnTakeDamage )
  end
end
--]]
